<template>
	<view class="main">
		<zmm-watermark :watermark="watermark"></zmm-watermark>
		<h2>修改密码</h2>
		<view class="msg">修改密码后,需要重新登录</view>
		<ul class="info">
			<li>
				<view class="msg">旧密码</view>
				<view class="txt">
					<input v-model="oldpassword" type="text" value="" password />
				</view>
			</li>
			<li>
				<view class="msg">新密码</view>
				<view class="txt">
					<input v-model="newpassword" type="text" value="" password />
				</view>
			</li>
			<li>
				<view class="msg">确认密码</view>
				<view class="txt">
					<input v-model="confirmNew" type="text" value="" password />
				</view>
			</li>
		</ul>
		<view class="btn">
			<view class="in" @tap="confirm">确认修改</view>
		</view>
	</view>
</template>

<script>
import { innerinfo, profile, changepwd } from '@/api/inner.js';
export default {
	data() {
		return {
			oldpassword: '',
			newpassword: '',
			confirmNew: '',
			watermark:'',
		};
	},
	onLoad() {
		this.watermark = uni.getStorageSync('watermark')
	},
	methods: {
		async confirm() {
			if (this.oldpassword.length == 0) {
				uni.showToast({
					title: '请输入旧密码',
					icon: 'none'
				});
				return;
			} else if (this.newpassword.length == 0) {
				uni.showToast({
					title: '请输入新密码',
					icon: 'none'
				});
				return;
			} else if (this.newpassword != this.confirmNew) {
				uni.showToast({
					title: '两次密码输入不一致',
					icon: 'none'
				});
				return;
			} else if (this.newpassword.length < 6) {
				uni.showToast({
					title: '新密码最少为六位数',
					icon: 'none'
				});
				return;
			} else {
				console.log(this.newpassword)
				let res = await changepwd({
					oldpassword: this.oldpassword,
					newpassword: this.newpassword
				});
				if (res.code == 1) {
					uni.showToast({
						title: '修改成功',
						icon: 'none'
					});
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}, 1000);
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
				}
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.main {
	padding: 30px 15px 0;
	h2 {
		font-size: 26px;
		color: #232323;
		font-weight: 700;
		margin-bottom: 15px;
	}
	.info {
		width: 100%;
		background-color: #fff;
		margin-bottom: 15px;
		li {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 10px 10px;
			color: #3d3d3d;
			position: relative;
			.txt {
				width: 70%;
				color: #3d3d3d;
			}
			.msg {
				width: 30%;
				margin-right: 20px;
			}
			.right {
				width: 15px;
				height: 15px;
				position: absolute;
				right: 10px;
			}
			input {
				padding: 0 5px;
				height: 40px;
				background-color: #f9f9f9;
				border-radius: 10px;
			}
		}
	}
	.btn {
		width: 100%;
		padding: 0 50px;
		.in {
			width: 100%;
			padding: 16px;
			text-align: center;
			color: #fff;
			background-color: #0c80fb;
			border-radius: 100px;
		}
	}
}
</style>
